package de.hhkk.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class FormatHelper
{

    private static String DATE_TIME_FORMAT = "dd.MM.yyyy - hh:mm";
    private static String DATE_FORMAT      = "dd.MM.yyyy";

    public static String formatDateToDateTimeString(Date pDate)
    {
        if (pDate != null)
        {
            SimpleDateFormat format = new SimpleDateFormat(DATE_TIME_FORMAT);
            String date = format.format(pDate);

            return date;
        }

        return null;
    }

    public static String formatDateToDateString(Date pDate)
    {
        if (pDate != null)
        {
            SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
            String date = format.format(pDate);

            return date;
        }

        return null;
    }

    public static Calendar formatDateToCalendar(Date pDate)
    {
        if (pDate != null)
        {
            Calendar cal = Calendar.getInstance();
            cal.setTime(pDate);

            return cal;
        }

        return null;
    }

    public static Date formatCalendarToDate(Calendar pCal)
    {
        if (pCal != null)
        {
            java.sql.Date sqlDate = new java.sql.Date(pCal.getTime().getTime());

            return sqlDate;
        }

        return null;
    }

    public static String formatCalendarToString(Calendar pCal)
    {
        if (pCal != null)
        {
            SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT);
            String date = format.format(pCal.getTime());

            return date;
        }

        return null;
    }
    
    public static int booleanToInt(boolean b) 
    {
        return b ? 1 : 0;
    }
}
